<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        :permission="permissionList"
        v-model="form"
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :before-open="beforeOpen"
	:row-style="rowStyle"
      >
        <template slot="menuLeft">
          <el-button type="primary" size="small" @click="addsObj"
            >添加</el-button
          >
          <el-button type="primary" size="small" @click="delsObj"
            >删除</el-button
          >
          <el-button type="primary" size="small" @click="merge">合并</el-button>
          <el-button type="primary" size="small" @click="handleExport"
            >导出</el-button
          >
          <el-button type="primary" size="mini" @click="submitData">加入报表差错</el-button>
          <div style="padding-left: 30px;display:inline-block;">
            <span style="color: red;font-size: 12px">提示：1.针对同一售票员、同一收益日期及设备操作号，不同班次的两条数据需保证所有数据已录入，且客值确认后，合并提交；</span>
	    <br/><span style="color: red;font-size: 12px;padding-left: 37px;">2.针对不同售票员、同一收益日期及设备操作号，需保证所有数据已录入，且客值确认后，合并提交。</span>
	    <br/><span style="color: red;font-size: 12px;padding-left: 37px;">3.客值信息确认完成后，若需再次修改车站配票、售票员日结算数据及乘客事务等信息时，需在修改完成后再次进行客值信息确认，<br/>否则会造成售票员信息提交不完整。</span>
          </div>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button
            icon="el-icon-edit"
            size="mini"
            type="text"
            v-if="editIsVis(scope.row)"
            @click="myEdit(scope.row)"
            >编辑</el-button
          >
          <el-button
            icon="el-icon-edit"
            size="mini"
            type="text"
            v-if="editIsViss(scope.row)"
            @click="mergeEdit(scope.row)"
            >编辑</el-button
          >
          <el-button
            type="text"
            size="mini"
            icon="el-icon-view"
            @click="myView(scope.row)"
            >预览</el-button
          >
          <el-button
            icon="el-icon-check"
            :size="scope.size"
            :type="scope.type"
            v-if="scope.row.approvalStatus == '0'"
            @click="toYX(scope.row)"
            >转账团购录入</el-button
          >
          <el-button
            icon="el-icon-check"
            :size="scope.size"
            :type="scope.type"
            v-if="scope.row.approvalStatus == '0'"
            @click="toCK(scope.row)"
            >乘客事务录入</el-button
          >
          <el-button
            icon="el-icon-check"
            :size="scope.size"
            :type="scope.type"
            @click="openPastRecords(scope.row)"
            >查看历史记录</el-button
          >
        </template>
      </avue-crud>
    </basic-container>
    <open-dialog
      :DialogVisible.sync="addVisableDialog"
      title="添加"
      width="60%"
    >
      <el-form v-if="addVisableDialog">
        <avue-form
          ref="form"
          v-model="formAdd"
          :option="tableOptionAdd"
          style="margin-bottom:40px;"
        ></avue-form>
        <div class="bottom-menu">
          <el-button type="primary" @click="save">保存</el-button>
          <el-button type="primary" @click="addVisableDialog = false"
            >取消</el-button
          >
        </div>
      </el-form>
    </open-dialog>
    <open-dialog
      :DialogVisible.sync="visableDialogRecords"
      title="查看历史记录"
      width="60%"
    >
      <avue-crud
        :data="recordsData"
        :option="tableOptionRecords">
      </avue-crud>
      <div class="bottom-menu-close">
        <el-button type="primary" @click="visableDialogRecords=false"
          >取消</el-button
        >
      </div>
    </open-dialog>
    <open-dialog
      :DialogVisible.sync="editVisableDialog"
      title="编辑"
      width="60%"
    >
      <el-form label-width="60px">
        <avue-form
          ref="form"
          v-model="conductorSettle"
          :option="tableOptionEdit"
          style="margin-bottom:40px;"
        ></avue-form>
        <!-- <div class="header">营销车票明细</div>
        <el-tabs v-model="activeName">
          <el-tab-pane label="线下正常售卖(售票员)" name="first">
            <avue-crud
              :data="tableDataOffine"
              :option="tableOptionOffine"
            ></avue-crud>
          </el-tab-pane>
          <el-tab-pane label="线下取票明细" name="second">
            <avue-crud
              :data="tableDataOffineTicket"
              :option="tableOptionOffineTicketView"
            >
              <template slot="receiptFilePath" slot-scope="{ row }">
                <el-link
                  type="primary"
                  :href="row.receiptFilePath"
                  v-if="row.receiptFilePath != null"
                  >下载</el-link
                >
              </template>
            </avue-crud>
          </el-tab-pane>
          <el-tab-pane label="团购售卖" name="third">
            <avue-crud :data="tableDataGroup" :option="tableOptionGroupView">
              <template slot="receiptFilePath" slot-scope="{ row }">
                <el-link
                  type="primary"
                  :href="row.receiptFilePath"
                  v-if="row.receiptFilePath != null"
                  >下载</el-link
                >
              </template>
            </avue-crud>
          </el-tab-pane>
        </el-tabs> -->
        <div class="bottom-menu-edit">
          <el-button type="primary" @click="edit">保存</el-button>
          <el-button type="primary" @click="editVisableDialog = false"
            >取消</el-button
          >
        </div>
      </el-form>
    </open-dialog>
    
    <open-dialog
      :DialogVisible.sync="mergeEditVisableDialog"
      title="编辑"
      width="60%"
    >
      <el-form label-width="60px">
        <avue-form
          ref="form"
          v-model="mergeEditForm"
          :option="tableOptionMergeEdit"
        ></avue-form>
        <div class="bottom-menu-edit">
          <el-button type="primary" @click="mergeEditSubmit">保存</el-button>
          <el-button type="primary" @click="mergeEditVisableDialog = false"
            >取消</el-button
          >
        </div>
      </el-form>
    </open-dialog>

    <open-dialog
      :DialogVisible.sync="viewVisableDialog"
      title="预览"
      width="60%"
    >
      <el-form label-width="40px">
        <avue-form
          v-model="conductorSettle"
          :option="tableOptionView"
          style="margin-bottom:40px;"
        ></avue-form>
        <!-- <div class="header">营销车票明细</div>
        <el-tabs v-model="activeName">
          <el-tab-pane label="线下正常售卖(售票员)" name="first">
            <avue-crud
              :data="tableDataOffine"
              :option="tableOptionOffine"
            ></avue-crud>
          </el-tab-pane> 
          <el-tab-pane label="线下取票明细" name="second">
            <avue-crud
              :data="tableDataOffineTicket"
              :option="tableOptionOffineTicketView"
            >
              <template slot="receiptFilePath" slot-scope="{ row }">
                <el-link
                  type="primary"
                  :href="row.receiptFilePath"
                  v-if="row.receiptFilePath != null"
                  >下载</el-link
                >
              </template>
            </avue-crud>
          </el-tab-pane>
          <el-tab-pane label="团购售卖" name="third">
            <avue-crud :data="tableDataGroup" :option="tableOptionGroupView">
              <template slot="receiptFilePath" slot-scope="{ row }">
                <el-link
                  type="primary"
                  :href="row.receiptFilePath"
                  v-if="row.receiptFilePath != null"
                  >下载</el-link
                >
              </template>
            </avue-crud>
          </el-tab-pane>
        </el-tabs> -->
        <div class="bottom-menu-edit">
          <el-button type="primary" @click="viewVisableDialog = false"
            >取消</el-button
          >
        </div>
      </el-form>
    </open-dialog>
    <open-dialog
      :DialogVisible.sync="mergeVisableDialog"
      title="选择合并后班次"
      width="30%"
    >
      <el-form>
        <avue-form
          ref="form"
          v-model="mergeForm"
          :option="mergeShiftsOption"
        ></avue-form>
        <div class="bottom-menu-close">
          <el-button type="primary" size="small" @click="mergeSubmit">保存</el-button>
          <el-button type="primary" size="small" @click="mergeVisableDialog = false"
            >取消</el-button
          >
        </div>
      </el-form>
    </open-dialog>
    <addReportEditor ref="addReportEditor" @addReportSuccess="getList"></addReportEditor>
  </div>
</template>

<script>
import {
  fetchList,
  getObj,
  addObj,
  putObj,
  putMerge,
  delObj,
  exportExcel,
  getMarketId,
  getMarketDetail,
  getConductorAdvancePayment,
  mergeObj,
  delBatch,
  queryConductorsettle,
  dataExport,
  getpassengerwork
} from "@/api/subwaystm/swstconductorsettle";
import {
  tableOptionGroup,
  tableOptionGroupView
} from "@/const/crud/subwaystm/swstmarketingticket/swstmarketingticketgroupsell";
import { tableOptionOffine } from "@/const/crud/subwaystm/swstmarketingticket/swstmarketingticketoffinesell";
import {
  tableOptionOffineTicket,
  tableOptionOffineTicketView
} from "@/const/crud/subwaystm/swstmarketingticket/swstmarketingticketoffinetaketicket";
import {
  tableOption,
  tableOptionAdd,
  tableOptionView,
  tableOptionEdit,
  tableOptionRecords,
  tableOptionMergeEdit
} from "@/const/crud/subwaystm/swstconductorsettle";
import { mapGetters } from "vuex";
import baseCrud from "@/mixins/base-crud";
import { dateFormat } from "@/util/date";
import { getByUserCode } from "@/api/admin/user";
import transitUtil from "@/api/subwayRat/transitUtil";
import { handleExcelResponse } from "@/util/util";
import addReportEditor from '@/views/stationTiecketManager/xianWngCJXXQR/BBCCGG/BBCCGGSQ/Editor';

export default {
  name: "swstconductorsettle",
  mixins: [baseCrud("subwaystm/swstconductorsettle")],
  components: {
    addReportEditor
  },
  data() {
    return {
      activeName: "second",
      tableOptionAdd: tableOptionAdd,
      tableOptionView: tableOptionView,
      tableOptionEdit: tableOptionEdit,
      tableOptionGroup: tableOptionGroup,
      tableOptionGroupView: tableOptionGroupView,
      tableOptionOffine: tableOptionOffine,
      tableOptionOffineTicket: tableOptionOffineTicket,
      tableOptionOffineTicketView: tableOptionOffineTicketView,
      addVisableDialog: false,
      editVisableDialog: false,
      viewVisableDialog: false,
      //tableDataOffine: [],
      tableDataOffineTicket: [],
      tableDataGroup: [],
      searchForm:{
        approvalStatus:'0'
      },
      idetailId: 0,
      form: {},
      conductorSettle: {},
      formAdd: {},
      deviceOperateNums:'',
      recordsData: [],
      visableDialogRecords: false,
      tableOptionRecords: tableOptionRecords,
      mergeEditForm: {},
      mergeEditVisableDialog: false,
      tableOptionMergeEdit: tableOptionMergeEdit,
      mergeVisableDialog: false,
      mergeForm: {},
      mergeShiftsOption: {
        menuBtn: false,
        labelWidth: 150,
        column: [
          // {
          //   type: "input",
          //   label: "售票员姓名",
          //   prop: "conductorName1",
          //   disabled: true
          // },{
          //   type: "select",
          //   label: "售票员班次",
          //   prop: "conductorShifts1",
          //   dicUrl: "/admin/dict/type/stm_conductor_shift",
          //   disabled: true
          // },{
          //   type: "input",
          //   label: "售票员姓名",
          //   prop: "conductorName2",
          //   disabled: true
          // },{
          //   type: "select",
          //   label: "售票员班次",
          //   prop: "conductorShifts2",
          //   dicUrl: "/admin/dict/type/stm_conductor_shift",
          //   disabled: true
          // },
          {
            type: "select",
            label: "合并后售票员班次",
            prop: "conductorShifts",
            dicUrl: "/admin/dict/type/stm_conductor_shift",
            span: 22,
            rules: [
              {
                required: true,
                message: "请选择合并后售票员班次"
              }
            ]
          }]
      },
      selectKeys:[]
    };
  },
  watch: {
    advancePaymentForm() {
      this.getConductorAdvanceForm();
    }
  },
  created() {
    this.otherVueAction();
  },
  mounted: function() {
    this.$nextTick(function() {
      if (this.$route.query.dialogFlag) {
        this.$refs.crud.rowAdd();
      }
    });
  },
  computed: {
    ...mapGetters(["permissions"]),
    permissionList() {
      return {
        addBtn: this.vaildData(
          this.permissions.stm_sw_st_conductor_settle_add,
          false
        ),
        delBtn: this.vaildData(
          this.permissions.stm_sw_st_conductor_settle_del,
          false
        ),
        editBtn: this.vaildData(
          this.permissions.stm_sw_st_conductor_settle_edit,
          false
        )
      };
    },
    advancePaymentForm() {
      return {
        conductorPersonJobNo: this.form.conductorJobNo,
        deviceOperateNum: this.form.deviceOperateNum,
        handTimeDTO: this.form.settleTime
      };
    }
  },
  methods: {
    async submitData() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.error("请选择数据");
        return false;
      }
      if (this.$refs.crud.tableSelect.length != 1) {
        this.$message.error("只能选择一条数据");
        return false;
      }
      let res = false;
      let ress = false;
      for (const table of this.$refs.crud.tableSelect) {
        if (table.approvalStatus != "1") {
          this.$message.error("请选择已提交的数据");
          return false;
        }else{
          if (table.isAddReprotError == "1") {
            res = await this.$confirm('该数据已加入报表差错，是否重新加入？', '提示', {
              confirmButtonText: '是',
              cancelButtonText: '否',
              type: 'warning'
            });
            if (!res) {
              return;
            }else{
              ress = true;
            }
          }
        }
      }
      if(res==false){
        ress = await this.$confirm("是否加入报表差错", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        });
      }
      if (!ress) {
        return;
      }
      this.selectKeys = this.$refs.crud.tableSelect;
      let param={
        dialogTitle: "加入报表差错",
        diffAmountId:this.selectKeys[0].id,
        dataSourceTable:"sw_st_conductor_settle",
        lineCode:this.selectKeys[0].lineCode,
        stationCode:this.selectKeys[0].stationCode,
        bomCode:this.selectKeys[0].bomCode,
        reprotTime:this.selectKeys[0].settleTime,
        reportNameId:1,
        deviceNo:this.selectKeys[0].deviceOperateNum,
        settleBeginTime:this.selectKeys[0].settleTime,
        settleEndTime:this.selectKeys[0].settleTime,
        userCodes:this.selectKeys[0].conductorJobNo,
        showType:3,
        dataSource:1,
        page:this.page
      };
      this.$refs.addReportEditor.others_report_add_call(param);
    },
    async queryPastRecords(row){
      let param={};
      param.id=row.id;
      var that = this
      await queryConductorsettle(param)
        .then(res => {
          this.recordsData = res.data.data;
        })
    },
    openPastRecords(row){
      this.queryPastRecords(row);
      this.visableDialogRecords=true;
    },
    editIsVis(row) {
      if (row.isMerge == '1') {
        return false;
      } else {
        if (row.approvalStatus == 1) {
          return false;
        } else {
          return true;
        }
      }
    },
    editIsViss(row) {
      if (row.isMerge == '0') {
        return false;
      } else {
        if (row.approvalStatus == 1) {
          return false;
        } else {
          return true;
        }
      }
    },
    delsObj: function() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.error("请选择数据");
        return false;
      }
      let ids = [];
      for (const table of this.$refs.crud.tableSelect) {
        if (table.approvalStatus != "0") {
          this.$message.error("请选择未提交的数据");
          return false;
        }
        if (table.reportModifyStatus == "1") {
          this.$message.error("报表修改状态为“是”的情况下，不允许删除数据");
          return false;
        }
        ids.push(table.id);
      }
      delBatch(ids)
        .then(data => {
          this.$message.success("删除成功");
          this.getList(this.page);
          done();
        })
        .catch(() => {});
    },
    merge(){
      if (this.$refs.crud.tableSelect.length != 2) {
        this.$message.error("请选择两条数据");
        return false;
      }
      const table1= this.$refs.crud.tableSelect[0];
      const table2 =this.$refs.crud.tableSelect[1];
      if (table1.confirmStatus != "1" || table2.confirmStatus != "1") {
          this.$message.error("只能选择已确认的数据进行合并！");
          return false;
      }
      if (table1.settleTime != table2.settleTime) {
          this.$message.error("只能选择同一天的数据进行合并！");
          return false;
      }
      if (table1.deviceOperateNum != table2.deviceOperateNum) {
          this.$message.error("只能选择相同设备操作号的数据进行合并！");
          return false;
      }  
      this.$confirm("如为上岗期间发现账号误用，需在备注栏进行说明，由线网确认，请确认是否继续操作", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.mergeVisableDialog = true;
      });
    },
    mergeSubmit: function() {
      if(this.mergeForm.conductorShifts == null || this.mergeForm.conductorShifts == undefined || this.mergeForm.conductorShifts == ""){
        this.$message.error("请选择合并后售票员班次！");
        return false;
      }
      let ids = [];
      for (const table of this.$refs.crud.tableSelect) {
        ids.push(table.id);
      }
      this.$confirm("确认合并数据？")
        .then(_ => {
          let Shifts = this.mergeForm.conductorShifts;
          mergeObj(ids,Shifts)
            .then(data => {
              this.$message.success("合并成功");
              this.getList(this.page);
              this.mergeVisableDialog = false;
              done();
            })
            .catch(() => {});
        })
        .catch(_ => {
          this.$refs.crud.toggleSelection();
        });
    },
    getConductorAdvanceForm() {
      if (
        this.advancePaymentForm.conductorPersonJobNo &&
        this.advancePaymentForm.deviceOperateNum
      ) {
        let query = Object.assign({ size: -1 }, this.advancePaymentForm);
        getConductorAdvancePayment(query).then(response => {
          let list = response.data.data.records;
          let advanceAmount = 0;
          list.forEach(l => (advanceAmount += l.adavncePayment));
          this.form.adanceAmount = advanceAmount;
        });
      }
    },

    //自定义编辑 预览方法
    myView: function(row) {
      var this_ = this;
      getObj(row.id)
        .then(response => {
          let res = response.data.data;
          this.conductorSettle = res;
        })
        .then(() => {
          getMarketId(
            Object.assign(
              {
                current: 1,
                size: -1
              },
              {
                conductorJobNo: this.conductorSettle.conductorJobNo,
                conductorShifts: this.conductorSettle.conductorShifts,
                opertorTime: this.conductorSettle.settleTime
              }
            )
          )
            .then(response => {
              this_.idetailId = row.id;
              if (response.data.data.records[0]) {
                this_.idetailId = response.data.data.records[0].id;
              }
            })
            .then(() => {
              getMarketDetail(this_.idetailId).then(response => {
                let res = response.data.data;
                // if (res.ticketOffineSells != null) {
                //   this.tableDataOffine = res.ticketOffineSells;
                // } else {
                //   this.tableDataOffine = [];
                // }

                if (res.ticketOffineSells != null) {
                  for (const item of res.ticketOffineSells) {
                    if (item.receiptFilePath != null) {
                      item.receiptFilePath =
                        "/admin/sys-file/" + item.receiptFilePath;
                    }
                  }
                  this.tableDataOffineTicket = res.ticketOffineTakeTickets;
                } else {
                  this.tableDataOffineTicket = [];
                }
                if (res.ticketGroupSells != null) {
                  for (const item of res.ticketGroupSells) {
                    if (item.receiptFilePath != null) {
                      item.receiptFilePath =
                        "/admin/sys-file/" + item.receiptFilePath;
                    }
                  }
                  this.tableDataGroup = res.ticketGroupSells;
                } else {
                  this.tableDataGroup = [];
                }
              });
            });
        })
        .then(() => {
          this.viewVisableDialog = true;
        });    
    },
     //颜色特殊标识
     rowStyle({ row, column, rowIndex }) {
      if (row.isNeedMerge == "1") {
        return {
          backgroundColor: "#eee",
          color: "red",
        };
      }
    },
    addsObj: function(){
      for (var i in this.formAdd) {
        this.formAdd[i] = null;
      }
      let startTime = new Date();
      let endTime = new Date();
      if (startTime.getHours() < 6) {
        startTime.setDate(startTime.getDate() - 1);
      }
      if (endTime.getHours() >= 6) {
        endTime.setDate(endTime.getDate() + 1);
      }
       //初始上岗默认时间
     let initGuardTime = new Date();     
      setTimeout(() => {
        (this.formAdd.workingStartTime = dateFormat(startTime).substr(0, 10) + " 02:00:00"),
	(this.formAdd.guardTime = dateFormat(initGuardTime).substring(0, 20)),
        (this.formAdd.workingEndTime = dateFormat(endTime).substr(0, 10) + " 01:59:59"),
        (this.formAdd.settleTime = dateFormat(startTime).substring(0, 10));
      }, 0);
      this.addVisableDialog = true;
    },
    async getUserDeviceOperateNo(parames){
      await getByUserCode(parames)
        .then((response) => {
          this.deviceOperateNums = response.data.data.deviceOperateNo;
        })
    },
    save: function() {
      let now = new Date();
      if (now.getHours() < 6) {
        now.setDate(now.getDate() - 1);
      }
      //增加验证结算周期范围     
      let dateStart = new Date(this.formAdd.workingStartTime);
      let dateEnd = new Date(this.formAdd.workingEndTime);    
      if (dateEnd.getHours() < 2) {       
	dateEnd.setDate(dateEnd.getDate() - 1);      
      }     
      if (dateFormat(dateStart).substr(0, 10) != dateFormat(dateEnd).substr(0, 10)) {      
	this.$message.info("结算周期时间范围必须是同一天！");
        return;
      }
      if (this.formAdd.workingStartTime>this.formAdd.workingEndTime) {      
	this.$message.info("结算结束时间不能小于结算开始时间！");
        return;
      }
      
      if(this.formAdd.settleTime < dateFormat(dateStart).substring(0, 10) || this.formAdd.settleTime > dateFormat(dateEnd).substring(0, 10)){
        this.$message.info("收入日期没在结算周期之内！");
        return;
      }     
      this.$refs.form.validate(vaild=>{
        if(vaild){
          this.getUserDeviceOperateNo(this.formAdd.conductorJobNo).then(() => {
            if(this.formAdd.deviceOperateNum!=this.deviceOperateNums){
              this.$confirm("请检查所选择的设备操作号与该售票员不匹配，是否确定保存？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
              }).then(() => {
                if(this.formAdd.settleTime != dateFormat(now).substring(0, 10)){
                  this.$confirm("收入日期不是系统默认时间,是否保存？", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                  }).then(() => {
                    addObj(this.formAdd)
                      .then(data => {
                        this.$message.success("添加成功");
                        this.getList(this.page);
                        this.addVisableDialog = false;
                        done();
                      })
                      .catch(() => {

                      });
                  })
                } else {
                  addObj(this.formAdd)
                    .then(data => {
                      this.$message.success("添加成功");
                      this.getList(this.page);
                      this.addVisableDialog = false;
                      done();
                    })
                    .catch(() => {
                    });
                }
              });
            }else{
              if(this.formAdd.settleTime != dateFormat(now).substring(0, 10)){
                this.$confirm("收入日期不是系统默认时间,是否保存？", "提示", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning"
                }).then(() => {
                  addObj(this.formAdd)
                    .then(data => {
                      this.$message.success("添加成功");
                      this.getList(this.page);
                      this.addVisableDialog = false;
                      done();
                    })
                    .catch(() => {
                    });
                })
              } else {
                addObj(this.formAdd)
                  .then(data => {
                    this.$message.success("添加成功");
                    this.getList(this.page);
                    this.addVisableDialog = false;
                    done();
                  })
                  .catch(() => {
                  });
              }
            }
          });
        }
      })
    },
    mergeEdit(row){
      getObj(row.id).then(response => {
        let res = response.data.data;
        this.mergeEditForm = res;
      })
      .then(() => {
        this.mergeEditVisableDialog = true;
      });

    },
    myEdit: function(row) {
      this.tableOptionEdit.column[6].disabled = false;
      this.tableOptionEdit.column[10].disabled = false;
      this.tableOptionEdit.column[13].disabled = false;
      this.tableOptionEdit.column[14].disabled = false;
      if(row.isAddReprotError=='1'){
        this.tableOptionEdit.column[6].disabled = true;
        this.tableOptionEdit.column[10].disabled = true;
        this.tableOptionEdit.column[13].disabled = true;
        this.tableOptionEdit.column[14].disabled = true;
      }
      var this_ = this;
      getObj(row.id)
        .then(response => {
          let res = response.data.data;
          this_.conductorSettle = res;
        })
        .then(() => {
          getMarketId(
            Object.assign(
              {
                current: 1,
                size: -1
              },
              {
                conductorJobNo: this.conductorSettle.conductorJobNo,
                conductorShifts: this.conductorSettle.conductorShifts,
                opertorTime: this.conductorSettle.settleTime
              }
            )
          )
            .then(response => {
              if (response.data.data.records[0]) {
                this_.idetailId = response.data.data.records[0].id;
              }
            })
            .then(() => {
              getMarketDetail(this_.idetailId).then(response => {
                let res = response.data.data;

                // if (res.ticketOffineSells != null) {
                //   this.tableDataOffine = res.ticketOffineSells;
                // } else {
                //   this.tableDataOffine = [];
                // }

                if (res.ticketOffineSells != null) {
                  for (const item of res.ticketOffineSells) {
                    if (item.receiptFilePath != null) {
                      item.receiptFilePath =
                        "/admin/sys-file/" + item.receiptFilePath;
                    }
                  }
                  this.tableDataOffineTicket = res.ticketOffineTakeTickets;
                } else {
                  this.tableDataOffineTicket = [];
                }
                if (res.ticketGroupSells != null) {
                  for (const item of res.ticketGroupSells) {
                    if (item.receiptFilePath != null) {
                      item.receiptFilePath =
                        "/admin/sys-file/" + item.receiptFilePath;
                    }
                  }
                  this.tableDataGroup = res.ticketGroupSells;
                } else {
                  this.tableDataGroup = [];
                }
              });
            });
        })
        .then(() => {
          this.editVisableDialog = true;
        });
    },
    mergeEditSubmit() {
      this.$refs.form.validate(vaild=>{
        if(vaild){
          putMerge(this.mergeEditForm)
            .then(data => {
              this.$message.success("修改成功");
              this.getList(this.page);
              this.mergeEditVisableDialog = false;
              done();
            })
            .catch(() => {});
        }
      })
    },
    edit: function() {
      if (
        this.conductorSettle.conductorJobNo == null ||
        this.conductorSettle.conductorShifts == "" ||
        this.conductorSettle.realAmount == null ||
        this.conductorSettle.bomCode == "" ||
        this.conductorSettle.workingStartTime == null ||
        this.conductorSettle.settleTime == null
      ) {
        this.$message.info(
          "售票员姓名、班次、实收金额、BOM编号、开始时间、结算时间为必填项！不能为空"
        );
        return;
      }
      putObj(this.conductorSettle)
        .then(data => {
          this.$message.success("修改成功");
          this.getList(this.page);
          this.editVisableDialog = false;
          done();
        })
        .catch(() => {});
    },
    toYX(row) {
      this.$router.push({
        path: "/swstmarketingticket",
        query: {
          dialogFlag: true,
          conductorName: row.conductorName,
          conductorJobNo: row.conductorJobNo,
          conductorShifts: row.conductorShifts,
          settleTime: row.settleTime,
          deviceOperateNum: row.deviceOperateNum,
          bomCode: row.bomCode
        }
      });
    },
    toCK(row) {
      let res = {};
      getpassengerwork(row).then(response => {
        res = response.data.data;
      })
      .then(() => {
        if(res != null){
          this.$router.push({
            path: "/sw-st-passenger-work",
            query: {
              dialogFlag: 0,
              isMerge:res.isMerge,
              datas: res
              }
          });
        }else{
          this.$router.push({
            path: "/sw-st-passenger-work",
            query: {
              dialogFlag: 1,
              conductorName: row.conductorName,
              conductorCode: row.conductorJobNo,
              classNumber: row.conductorShifts,
              workDate: row.settleTime,
              deviceOperateNum: row.deviceOperateNum,
              bomCode: row.bomCode
            }
          });
        }
      });
    },
    beforeOpen(show, type) {
      if (type == "add") {
        let startTime = new Date();
        let endTime = new Date();
        if (startTime.getHours() < 6) {
          startTime.setDate(startTime.getDate() - 1);
        }
        if (endTime.getHours() >= 6) {
          endTime.setDate(endTime.getDate() + 1);
        }
	 //初始上岗默认时间
	let initGuardTime = new Date();
        setTimeout(() => {
          (this.form.workingStartTime =
            dateFormat(startTime).substr(0, 10) + " 02:00:00"),
	    (this.form.guardTime = dateFormat(initGuardTime).substring(0, 20)),
            (this.form.workingEndTime = dateFormat(endTime).substr(0, 10) + " 01:59:59"),
            (this.form.settleTime = dateFormat(startTime).substring(0, 10));
        }, 0);
        // let now = new Date()
        // if(now.getHours() < 6){
        //   now.setDate(now.getDate() - 1)
        // }
        // setTimeout(() => {
        //   this.form.workingStartTime = dateFormat(now),
        //   this.form.workingEndTime = dateFormat(now),
        //   this.form.settleTime = dateFormat(now).substring(0, 10)
        // }, 0)
      }
      show();
    },
    otherVueAction(){
      let th=this;
      transitUtil.$on('updateReport_call_1',(param)=>{
        let p=param;
        fetchList(p).then(response => {
          this.tableData = response.data.data.records
          this.page.total = response.data.data.total
          this.tableLoading = false
        })
      });
    },
    async handleExport(row) {
      this.dataExport();
    },
    async dataExport() {
      if (!this.searchForm.settleTime) {
        this.$message.error("选择完收入日期后点击查询按钮后再导出!");
        return;
      }
      let loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      try {
        const res = await dataExport(this.searchForm);
        if(res.data.size>0){
          handleExcelResponse(res);
        }else{
          this.$message.error("无数据导出！");
          return;
        }
        
      } finally {
        loading.close();
      }
    },
  }
};
</script>
<style lang="scss" scoped>
.header {
  margin: 0 auto;
  width: 99%;
  padding: 5px 10px;
  border: 1px solid #e4e4e4;
  border-bottom: none;
  background-color: #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.bottom-menu {
  margin-top: -48px;
  text-align: center;
}
.bottom-menu-close {
  margin-top: 18px;
  text-align: center;
}
.bottom-menu-edit {
  margin-top: 48px;
  text-align: center;
}
</style>
